package com.example.demolearn.dao;

import com.example.demolearn.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

@Repository  // 引起Spring容器的注意，通常用在存储相关的类上
public class UserDAO {

    @Autowired   // 注入
    JdbcTemplate jdbcTemplate;

    public User getUser(String id) {
        String sql = "select * from sys_user_role where userCode=?";
        User user = jdbcTemplate.queryForObject(sql, new RowMapper<User>() {
            public User mapRow(ResultSet rs, int rowNum) throws SQLException {
                User user = new User();
                return user;
            }
        }, id);
        return user;
    }
}
